import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:smart_devices/ui/my_custom_paint_line.dart';
import 'package:smart_devices/utils/colors.dart';
import 'package:smart_devices/utils/styles.dart';
import 'package:smart_devices/utils/tools.dart';

import 'document_logic.dart';

class DeviceDocumentView extends GetView<DeviceDocumentLogic> {
  const DeviceDocumentView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: IconButton(
          icon: const Icon(
            Icons.arrow_back_ios,
            color: Colors.white,
            size: 15,
          ),
          onPressed: Get.back,
        ),
        automaticallyImplyLeading: false,
        backgroundColor:
            ColorsUtils.parseColorFromHexString(ColorsUtils.color0052),
        title: Text(
          '关联文档',
          style: StylesUtils.customTextStyle(
              fontSize: 18, fontWeight: FontWeight.w700),
        ),
        centerTitle: true,
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [
            Container(
              margin: const EdgeInsets.only(top: 10),
              color: Colors.white,
              child: ListBody(
                children: [
                  SizedBox(
                    height: 40,
                    child: CustomPaint(
                        painter: MyCustomPaintLine(),
                        child: Container(
                          margin: const EdgeInsets.only(left: 30),
                          alignment: Alignment.centerLeft,
                          child: Text(
                            '关联文档',
                            style: StylesUtils.customTextStyle(
                                color: ColorsUtils.color6666),
                          ),
                        )),
                  ),
                  ...controller.files
                      .map((element) => Container(
                          height: 40,
                          alignment: Alignment.centerLeft,
                          padding: const EdgeInsets.symmetric(horizontal: 10),
                          child: Row(
                            children: [
                              Container(
                                width: 40,
                                alignment: Alignment.center,
                                margin: const EdgeInsets.only(right: 10),
                                child: Image(
                                  width: 25,
                                  height: 25,
                                  image: ToolsUtils.getFileIconByFilename(
                                      element.name),
                                ),
                              ),
                              Align(
                                alignment: Alignment.centerLeft,
                                child: Text(
                                  element.name,
                                  overflow: TextOverflow.ellipsis,
                                  style: StylesUtils.customTextStyle(
                                      color: ColorsUtils.color0052),
                                ),
                              )
                            ],
                          )))
                      .toList(),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}
